package Utils;
import lejos.nxt.TouchSensor;
import lejos.robotics.navigation.DifferentialPilot;


public class TouchSensorMethod {

	public static void alignWithTheWall (DifferentialPilot mRobot, TouchSensor mLeftTouchSensor, TouchSensor mRightTouchSensor) {
		
		while(!(mLeftTouchSensor.isPressed() && mRightTouchSensor.isPressed())) {
			
			mRobot.travel(30);
			int rotationWay = 0;
			
			if((mLeftTouchSensor.isPressed() && (!(mRightTouchSensor.isPressed())))) {
				rotationWay = 1;
			} else if (((!(mLeftTouchSensor.isPressed())) && mRightTouchSensor.isPressed())) {
				rotationWay = 2;
			}
			
			if(rotationWay != 0) {
				
				mRobot.travel(-3);
			
				if(rotationWay == 1) {
					mRobot.rotate(-5);
				} else if (rotationWay == 2) {
					mRobot.rotate(5);
				}
			}
			
		}
		
		mRobot.stop();
		mRobot.travel(3);
		mRobot.stop();
		mRobot.travel(-7);
		mRobot.stop();
	}
	
	
}
